<?php
    $this->layout('base.phtml', [
        'title' => _('Help & support'),
        'canonical' => url_full('support'),
        'current_page' => 'support',
        'has_errors' => $error || $errors,
    ]);
?>

<div class="section section--small section--longbottom">
    <div class="section__title">
        <h1><?= _('Help & support') ?></h1>
    </div>

    <p class="section__intro">
        <?= _('If you have a question or if you’re facing an issue, you can contact me via this form.') ?>
    </p>

    <form
        method="post"
        action="<?= url('call support') ?>"
        data-controller="autosave"
        data-action="turbo:submit-start@document->autosave#clear"
    >
        <?= $this->include('alerts/_error.phtml', ['message' => $error]) ?>

        <?php if ($message_sent): ?>
            <?= $this->include('alerts/_success.phtml', ['message' => _('Your message has been sent.')]) ?>
        <?php endif; ?>

        <input type="hidden" name="csrf" value="<?= csrf_token() ?>" />

        <div class="form-group <?= isset($errors['subject']) ? 'form-group--invalid' : '' ?>">
            <label for="subject">
                <?= _('Subject') ?>
            </label>

            <input
                id="subject"
                name="subject"
                type="text"
                value="<?= $subject ?>"
                required
                aria-describedby="subject-desc"
                data-action="keyup->autosave#save"
            />

            <div id="subject-desc">
                <?php if (isset($errors['subject'])): ?>
                    <p class="form-group__error">
                        <span class="sr-only"><?= _('Error') ?></span>
                        <?= $errors['subject'] ?>
                    </p>
                <?php endif; ?>
            </div>
        </div>

        <div class="form-group <?= isset($errors['message']) ? 'form-group--invalid' : '' ?>">
            <label for="message">
                <?= _('Your message') ?>
            </label>

            <textarea
                id="message"
                name="message"
                required
                data-controller="text-editor"
                data-action="text-editor#refresh keyup->autosave#save"
                aria-describedby="message-desc"
            ><?= $message ?></textarea>

            <div id="message-desc">
                <?php if (isset($errors['message'])): ?>
                    <p class="form-group__error">
                        <span class="sr-only"><?= _('Error') ?></span>
                        <?= $errors['message'] ?>
                    </p>
                <?php endif; ?>
            </div>
        </div>

        <p class="paragraph--placeholder">
            <?= _f('I’ll answer you at <strong>%s</strong>', protect($current_user->email)) ?>
        </p>

        <div class="form__actions">
            <button type="submit" class="button--primary">
                <?= _('Send your message') ?>
            </button>
        </div>
    </form>

    <hr />

    <h2 class="text--centered">
        <?= _('More help') ?>
    </h2>

    <div class="groupnav">
        <ul class="groupnav__container">
            <li class="groupnav__item groupnav__item--onboarding">
                <a class="groupnav__anchor" href="<?= url('onboarding') ?>">
                    <?= _('Start the onboarding again') ?>
                </a>
            </li>

            <li class="groupnav__item groupnav__item--whats-new">
                <a class="groupnav__anchor" href="<?= url('what is new') ?>">
                    <?= _('What’s new?') ?>
                </a>
            </li>

            <li class="groupnav__item groupnav__item--about">
                <a class="groupnav__anchor" href="<?= url('about') ?>">
                    <?= _f('About %s', get_app_configuration('brand')) ?>
                </a>
            </li>
        </ul>
    </div>
</div>
